package models

import (
	"time"
	"user_srv/basic/config"
)

type Face struct {
	Id        uint64    `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	UserId    int32     `gorm:"column:user_id;type:int;not null;" json:"user_id"`
	FaceImg   string    `gorm:"column:face_img;type:varchar(255);not null;" json:"face_img"`
	CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP;" json:"created_at"`
	UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null;default:CURRENT_TIMESTAMP;" json:"updated_at"`
	DeleteAt  time.Time `gorm:"column:delete_at;type:datetime;default:NULL;" json:"delete_at"`
}

func (f *Face) TableName() string {
	return "face"
}

func (f *Face) Create() error {
	return config.DB.Create(&f).Error
}

func (f *Face) GetByUserId() error {
	return config.DB.Where("user_id = ?", f.UserId).Limit(1).Find(&f).Error
}
func (f *Face) GetFaceList() (list []Face, err error) {
	err = config.DB.Find(&list).Error
	return
}
func (f *Face) UpdateFace() error {
	return config.DB.Updates(&f).Error
}
func (f *Face) DeleteFace() error {
	return config.DB.Delete(&f).Error
}
